﻿Imports Microsoft.DirectX
Imports Microsoft.DirectX.Direct3D
Public Class ObjektStringUpDown
    Inherits Objekt2D
    Const ReglerBreite As Integer = 16
    Dim Value As Integer
    Public ReadOnly Property GetValue() As String
        Get
            Return Tags(Value)
        End Get
    End Property
    Public Sub SetValue(ByVal Value As Integer)
        Me.Value = Value
        If Me.Value < 0 Then Me.Value = 0
        If Me.Value >= Tags.Length Then Me.Value = Tags.Length - 1
    End Sub
    Dim Namen As String() = {}
    Dim Tags() As String = {}

    Dim Text As ObjektText
    Dim Ausgewäht As Boolean
    Public Sub New(ByVal Startvalue As Integer, ByVal neuNamen As String(), ByVal Bild As String, ByVal Position As Point, ByVal Fixed As PointF, Optional ByVal Handler As ObjektPanel = Nothing)
        Me.New(Startvalue, neuNamen, Image.FromFile(Bild), Position, Bild, Fixed, Handler)
    End Sub
    Public Sub New(ByVal Startvalue As Integer, ByVal neuNamen As String(), ByVal Bild As Bitmap, ByVal Position As Point, ByVal Bildname As String, ByVal Fixed As PointF, Optional ByVal Handler As ObjektPanel = Nothing)
        MyBase.New(Bildname, New Rectangle(0, 0, Bild.Width, Bild.Height), Position, Fixed, Nothing)
        Value = Startvalue
        Bildgröße = New Rectangle(0, 0, 0, 20)
        Tags = neuNamen
        Array.Resize(Namen, Tags.Length)
        For I = 0 To Namen.Length - 1
            Namen(I) = Sprachconverter.Translate(Tags(I))
        Next
        Text = New ObjektText(New String() {Namen(Value)}, 2, 1, Nothing, "Arial", 14, FontStyle.Regular)
        For I = 0 To Namen.Length - 1
            Dim B As Integer = Text.GetSchriftart.MeasureString(Grafikengine.Sprite, Namen(I), DrawTextFormat.None, Color.Black).Width
            If B > Rechteck.Width Then
                Bildgröße.Width = B
            End If
        Next
        Bildgröße.Width += 4
        'Da Größen und andere Dinge erst noch berechnet wurden!
        Me.Handler = Handler
        If Me.Handler IsNot Nothing Then
            Me.Handler.AddObjekt(Me)
        End If
    End Sub
    Public Overrides Sub Malen()
        If Handler IsNot Nothing Then
            If Not Handler.IsVisible(New Rectangle(Koordinaten.X, Koordinaten.Y, Rechteck.Width + 16, Rechteck.Height), True) Then
                Exit Sub
            End If
        End If

        Dim sngRotation As Double = 0
        Dim intColor As Color = Color.FromArgb(255, 255, 255, 255)
        Grafikengine.ptfRotCenter = Nothing
        Grafikengine.szfScale = Nothing
        Grafikengine.ptfPosition = GetRealKoordinaten()
        With Grafikengine.recBild
            .X = 0 : .Width = 2
            .Y = 0 : .Height = 20
        End With
        Grafikengine.Sprite.Draw2D(Textur.getTextur(TexturID), Grafikengine.recBild, Grafikengine.szfScale, Grafikengine.ptfRotCenter, sngRotation, Grafikengine.ptfPosition, intColor)
        Text.Malen(Grafikengine.Sprite)
        Grafikengine.ptfPosition.X += Rechteck.Width + 15
        Grafikengine.recBild.X = 30
        Grafikengine.Sprite.Draw2D(Textur.getTextur(TexturID), Grafikengine.recBild, Grafikengine.szfScale, Grafikengine.ptfRotCenter, sngRotation, Grafikengine.ptfPosition, intColor)
        Grafikengine.ptfPosition.X = GetRealX() + 2
        With Grafikengine.recBild
            .X = 2 : .Width = 13
            .Y = 0 : .Height = 20
        End With
        Grafikengine.szfScale.Width = Rechteck.Width
        Grafikengine.szfScale.Height = 20
        Grafikengine.Sprite.Draw2D(Textur.getTextur(TexturID), Grafikengine.recBild, Grafikengine.szfScale, Grafikengine.ptfRotCenter, sngRotation, Grafikengine.ptfPosition, intColor)
        With Grafikengine.recBild
            .X = 16 : .Width = 14
            .Y = 0 : .Height = 20
        End With
        Grafikengine.szfScale = Nothing
        Grafikengine.ptfPosition.X = GetRealX() + 1 + Rechteck.Width
        Grafikengine.Sprite.Draw2D(Textur.getTextur(TexturID), Grafikengine.recBild, Grafikengine.szfScale, Grafikengine.ptfRotCenter, sngRotation, Grafikengine.ptfPosition, intColor)
    End Sub

    Public Overrides Function Keydown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) As Boolean

    End Function

    Public Overrides Function KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) As Boolean

    End Function

    Public Overloads Overrides Function MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) As Boolean
        If IsVisble(16) Then
            If (Not Objekt2D.AlreadyKlickt And Not HasFocus) Or Focused Then
                Dim P As Point = GetRealKoordinaten()
                Dim StartRechteck As New Rectangle(P.X + Rechteck.Width, P.Y, ReglerBreite, 6)
                If Rechteck.Contains(e.X, e.Y) Then
                    Objekt2D.AlreadyKlickt = True
                Else
                    If StartRechteck.Contains(e.X, e.Y) Then
                        Value += 1
                        If Value > Namen.Length - 1 Then
                            Value = Namen.Length - 1
                        End If
                        Text.neuerText(New String() {Namen(Value)}, 2, 1, Nothing)
                        Objekt2D.AlreadyKlickt = True
                        Return True
                    Else
                        StartRechteck.Y += 10
                        If StartRechteck.Contains(e.X, e.Y) Then
                            Value -= 1
                            If Value < 0 Then
                                Value = 0
                            End If
                            Text.neuerText(New String() {Namen(Value)}, 2, 1, Nothing)
                            Objekt2D.AlreadyKlickt = True
                            Return True
                        End If
                    End If
                End If
                Return False
            End If
        End If
    End Function

    Public Overloads Overrides Function MouseEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) As Boolean

    End Function

    Public Overloads Overrides Function MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) As String
        Return ""
    End Function
End Class
